﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLNHASACH.BussinessLayer;

namespace QLNHASACH.PresentationLayer.Controls
{
    public partial class HoaDonBanSachCtrl : UserControl
    {
        public HoaDonBanSachCtrl()
        {
            InitializeComponent();
            
        }

        private void txbTenKhachHang_TextChanged(object sender, EventArgs e)
        {
            if (txbTenKhachHang.Text != "")
            { 
                lboxKH.Datasource = KhachHangBUS.TimTheoTen(txbTenKhachHang.Text);
                if(lboxKH.Datasource!=null)
                    lboxKH.Visible = true;
            }
            else lboxKH.Visible = false;

        }
        void EnableEditting(bool editting)
        {
            btTao.Enabled = !editting;
            btLuu.Enabled = editting;
            btKhongLuu.Enabled = editting;

            txbTenKhachHang.Enabled = editting;
            ccbNgayLap.Enabled = editting;
            gbSach.Visible = editting;
        }

        private void HoaDonBanSachCtrl_Load(object sender, EventArgs e)
        {
            lboxKH.Visible = false;
            EnableEditting(false);
        }

        private void lboxKH_ItemClick()
        {
            txbTenKhachHang.Text = lboxKH.SelectedItem.Hoten;
            lboxKH.Visible = false;
        }

        private void btTao_Click(object sender, EventArgs e)
        {
            txbTenKhachHang.Text = "";
            EnableEditting(true);
        }

        private void btLuu_Click(object sender, EventArgs e)
        {
            EnableEditting(false);
        }

        private void btKhongLuu_Click(object sender, EventArgs e)
        {
            EnableEditting(false);
        }
    }
}
